" To add comments add one double quotes and a space:
set ttyfast  " to fast scrolling of hjkl
set wrap linebreak nolist
set foldmethod=manual " use zf to fold the selected lines, use zo or l to open and zd to delete them
set encoding=utf-8
set nocompatible
filetype plugin on
syntax on
" set mouse=a
set mouse+=a "for active mouse copied to clipboard
set relativenumber
set number
set tabstop=4
set shiftwidth=4
" set clipboard+=unnamedplus
call plug#begin('~/.config/nvim')
"let me see 
"to delete a Plug just delete it from here and call :PlugClean
Plug 'https://github.com/vim-airline/vim-airline' 
Plug 'nvim-lua/plenary.nvim' 
" Plug 'makerj/vim-pdf' 
" below plug finds the defination of variables, class, functions etc 
Plug 'gpanders/vim-medieval' "to evaluate markdown code blocks
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
Plug 'sheerun/vim-polyglot'
Plug 'jbyuki/quickmath.nvim' 
Plug 'Apeiros-46B/qalc.nvim'
" Plug 'itchyny/calendar.vim'
Plug 'mhinz/vim-startify'
Plug 'SirVer/UltiSnips'
Plug 'honza/vim-snippets'
Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
"to change welcome screen of neovim
Plug 'https://github.com/nvimdev/dashboard-nvim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'nvim-telescope/telescope.nvim' 
Plug 'https://github.com/BurntSushi/ripgrep' 
Plug 'https://github.com/sharkdp/fd'
Plug 'https://github.com/jiangmiao/auto-pairs'
Plug 'azabiong/vim-highlighter'
Plug 'https://github.com/preservim/nerdtree' "use PlugInstall if not installed, then use :NERDtree, :NERDTreefocus and enjoy
Plug 'https://github.com/tpope/vim-commentary' " used to put comments via gcc
Plug 'https://github.com/tpope/vim-surround' "used to see status
Plug 'https://github.com/ap/vim-css-color' " CSS Color Preview
Plug 'https://github.com/rafi/awesome-vim-colorschemes' " Retro Scheme
Plug 'https://github.com/neoclide/coc.nvim'  " Auto Completion
Plug 'https://github.com/preservim/tagbar' "press f8 to see
Plug 'https://github.com/tc50cal/vim-terminal' " Vim Terminal
" Plug 'https://github.com/terryma/vim-multiple-cursors' " CTRL + N for multiple cursors
Plug 'morhetz/gruvbox'
"above plugin are copied from NeuralNine youtube channel creator:
"https://github.com/NeuralNine/config-files/blob/master/init.vim
Plug 'https://github.com/kassio/neoterm'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" Add this line to your vimrc
Plug 'https://github.com/lervag/vimtex' 
" Plug 'duane9/nvim-rg' " it is dependency for live_grep. 
Plug 'https://github.com/ryanoasis/vim-devicons' " Developer Icons: always load this plug in the end. 

call plug#end()

"below lines are added for cuda 
au BufNewFile,BufRead *.cu set filetype=cuda
au BufNewFile,BufRead *.cuh set filetype=cuda
let mapleader=","
let maplocalleader = ","
" set my mapleader to "," if you want to know more about mapleader enter :h mapleader in Vim
inoremap jk <Esc>
let file_type = &filetype
let filepath = expand('%:p')
let filename = expand('%:t:r')

if file_type == 'vim'
nnoremap <leader>c :w<CR>:source $MYVIMRC<CR>
elseif file_type == 'c'
nnoremap <leader>c :w<CR>:!gcc <C-R>=filepath<CR> -o %:t:r <CR>:T bash<CR><CR>i
"&& time ./a.out<CR>
elseif file_type == 'cpp'
nnoremap <leader>c :w<CR>:!g++ <C-R>=filepath<CR> -o %:t:r <CR>:T bash<CR><CR>i
"&& time ./a.out<CR>
elseif file_type == 'cuda'
nnoremap <leader>c :w<CR>:!nvcc <C-R>=filepath<CR> -o %:t:r <CR>:T bash<CR><CR>i
"&& time ./a.out<CR>
elseif file_type == 'python'
nnoremap <leader>c :w<CR>:!python <C-R>=filepath<CR><CR>i:T bash<CR><CR>i
endif
"it turns out that to quickly open files we shall not execute init.vim each
"time, so I am calling the sourcing of init.vim only when we want to
"execute the code. 

" autocmd BufEnter *.c,*.cpp,*.cu,*.py if file_type ==# 'c' || file_type ==# 'cpp' || file_type ==# 'cuda' || file_type ==# 'python' | source $MYVIMRC | endif
" 
" The above commented auto reload did not work, it was 
"
" Your other custom mappings and configurations
"

" Autocommand to reload the configuration when a new buffer is loaded
" Auto-reload Vim configuration when switching between specific filetypes

" Other settings and configurations


"<CR> is used to press enter
" <C-R>= is used to insert the value of an expression. In this case, it's used to insert the value of g:current_file.


" please don't put space after the <esc> keyword above # to enter into normal mode just press jk in insert mode. 
" to run the cuda program after editing, just write the 'Rc' short for goto
" normal mode and run cuda.
"
" ********************IF you want to create specific executables with program
" name istead of ./a.out*************************************, 
"if file_type == 'vim'
" nnoremap <leader>r :w<CR>:source $MYVIMRC<CR>
" elseif file_type == 'c'
" nnoremap <leader>r :w<CR>:!gcc <C-R>=filepath<CR> -o %:t:r && time ./<C-R>=filename<CR><CR>
" elseif file_type == 'cpp'
" nnoremap <leader>r :w<CR>:!g++ <C-R>=filepath<CR> -o %:t:r && time ./<C-R>=filename<CR><CR>
" elseif file_type == 'cuda'
" nnoremap <leader>r :w<CR>:!nvcc <C-R>=filepath<CR> -o %:t:r && time ./<C-R>=filename<CR><CR>
" elseif file_type == 'python'
" nnoremap <leader>r :w<CR>:!python <C-R>=filepath<CR><CR>
" endif

"
" hi Normal ctermbg=16
set t_Co=256
" the above command is equivalent to ctrl+t to toggle NERDtree. 
" leader means "\" 


" I use below configuration for open and edit and reload my dot vimrc file:
nnoremap <leader>fmi :set foldmethod=indent<CR>

nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>ft :Telescope find_files<CR>
nnoremap <leader>fzf :FZF<CR>
" nnoremap <leader>tz :TerminalVSplit zsh<CR><CR>
"I am not using telescope for the moment and have setting fuzzyfinder which
"is triggered by keys 'fzf' in normal mode. you can uncomment telescope
"command to use that too. 
" nnoremap <leader>tv :TerminalVSplit bash<CR><CR>
" nnoremap <leader>t  :T bash<CR><CR>i
" nnoremap <leader>th :TerminalSplit bash<CR><CR>
nnoremap <leader>z :w!<CR>:suspend<CR> 
nnoremap <leader>ff :NERDTreeToggle<CR>
nnoremap <leader>nt :NERDTree<CR>
nnoremap <leader>vm :tabe $MYVIMRC<CR>
nnoremap <leader>ep :tabe /root/project1/SIMULATeQCD/src/examples/main_plaquette.cpp<CR>
nnoremap <leader>hyp :tabe /root/project1/SIMULATeQCD/src/modules/hyp/<CR>
nnoremap <leader>kn :tabe /root/project1/SIMULATeQCD/src/gauge/gauge_kernels.cpp<CR>

" Open my vimrc file in vertical tab whenever I pressed ,vm
nnoremap <leader>sv :w<CR>:source $MYVIMRC<CR>
inoremap <leader>sv <esc>:w<CR>:source $MYVIMRC<CR>i
tnoremap <leader>q <C-\><C-d>
tnoremap <leader>nw <C-w>w
" Reload my vimrc file whenever I pressed ,sv and we will go to normal mode,
" then source our vim file, and get back to insert mode.
nnoremap <leader>ss :w!<CR>   
" Save my current file with ,w instead of typing :w every time.
nnoremap<leader>q :q!<CR>
" to quit my file with ,q rather than with :q
nnoremap<leader>wq :wq!<CR>
nnoremap<leader>sq :wq!<CR>
" to save and quit the current fiile with ,wq rather than with :wq 
" 3<leader>tl will clear neoterm-3, use comma and tl to get terminal, insert
" commands and once done, hit exit enter,
" one alternative to use terminal after code is to use ctrl+z or set
" keybinding to ctrl+z to pause vim and play in terminal and use fg+enter to
" get back to where we were in vim.
" nnoremap <leader>tl :<c-u>exec v:count.'Tclear'<cr>
" let NERDTreeShowHidden=1
"To toggle between hidden files, use shift+i for the nerdtree. 
"
"the above command is set to show the hidden items of the directory
" :source $MYVIMRC
"
"
" let g:python3_host_prog = '/usr/bin/python'
" let g:python3_host_prog = '/Users/vishalrao/.pyenv/versions/3.9.10/bin/python3'
" uncomment the upper line for use in macOS.

let g:loaded_ruby_provider = 0
nnoremap <leader>dm :set background=dark<CR>:colorscheme gruvbox<CR>
"key to day/dark mode is just <leader>dm


nnoremap <leader>nm :set background=light<CR>:colorscheme morning<CR>
"  key for night mode is just <leader>nm
"
set background =dark
" set background=light
" :colorscheme PaperColor
" :colorscheme alduin
" :colorscheme deus 
" :colorscheme deep-space
" :codkfjorscheme apprentice
" :colorscheme flattened-dark
" :colorscheme flattened-lightline
" :colorscheme slate 
" :colorscheme sierra
" :colorscheme delek 
" :colorscheme desert
" :colorscheme nord 
" :colorscheme hybrid_material 
" :colorscheme molokayo 
" :colorscheme molokai  
" :colorscheme happy_hacking 
" :colorscheme materialbox 
" :colorscheme gotham 
:colorscheme gruvbox

" let g:NERDTreeDirArrowExpandable="+"
" let g:NERDTreeDirArrowCollapsible="~"
nnoremap <C-l> :call CocActionAsync('jumpDefinition')<CR>

nmap <F8> :TagbarToggle<CR>
:set completeopt-=preview " For No Previews
let g:airline_powerline_fonts = 1

if !exists('g:airline_symbols')
  let g:airline_symbols = {}
endif
" airline symbols
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''



"
"************************************LATEX SECTION OF init.vim***************************************
"
" This is necessary for VimTeX to load properly. The "indent" is optional.
" Note that most plugin managers will do this automatically.
filetype plugin indent on

let g:vimtex_view_method = 'zathura'
" This enables Vim's and neovim's syntax-related features. Without this, some
" VimTeX features will not work (see ":help vimtex-requirements" for more
" info).
syntax enable

" Viewer options: One may configure the viewer either by specifying a built-in
" viewer method:
let g:vimtex_view_method = 'zathura'

" Or with a generic interface:
let g:vimtex_view_general_viewer = 'okular'
let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'

" VimTeX uses latexmk as the default compiler backend. If you use it, which is
" strongly recommended, you probably don't need to configure anything. If you
" want another compiler backend, you can change it as follows. The list of
" supported backends and further explanation is provided in the documentation,
" see ":help vimtex-compiler".
let g:vimtex_compiler_method = 'latexrun'

" Most VimTeX mappings rely on localleader and this can be changed with the
" following line. The default is usually fine and is the symbol "\".



" ***********************************COC.NVIM******************************

" May need for Vim (not Neovim) since coc.nvim calculates byte offset by count
" utf-8 byte sequence
set encoding=utf-8
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup

" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
" delays and poor user experience
set updatetime=300

" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved
set signcolumn=yes

" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config
inoremap <silent><expr> <TAB>
    \ coc#pum#visible() ? coc#pum#next(1) :
    \ CheckBackspace() ? "\<Tab>" :
    \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
                            \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif

" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>

function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
  call CocActionAsync('doHover')
else
  call feedkeys('K', 'in')
endif
endfunction

" Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming
nmap <leader>rn <Plug>(coc-rename)

" Formatting selected code
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s)
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Applying code actions to the selected code block
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

" Remap keys for applying code actions at the cursor position
nmap <leader>ac  <Plug>(coc-codeaction-cursor)
" Remap keys for apply code actions affect whole buffer
nmap <leader>as  <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line
nmap <leader>fc  <Plug>(coc-fix-current)

" Remap keys for applying refactor code actions
nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
xmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)
nmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)

" Run the Code Lens action on the current line
nmap <leader>cl  <Plug>(coc-codelens-action)

" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)

" Remap <C-f> and <C-b> to scroll float windows/popups
if has('nvim-0.4.0') || has('patch-8.2.0750')
  nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif

" Use CTRL-S for selections ranges
" Requires 'textDocument/selectionRange' support of language server
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)

" Add `:Format` command to format current buffer
command! -nargs=0 Format :call CocActionAsync('format')

" Add `:Fold` command to fold current buffer
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer
command! -nargs=0 OR   :call     CocActionAsync('runCommand', 'editor.action.organizeImport')

" Add (Neo)Vim's native statusline support
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Mappings for CoCList
" Show all diagnostics
nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item
nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item
nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>




"******************VIM-SNIPPETS and UltiSnips**************
" For example, I use the following configuration:
" let g:UltiSnipsSnippetDirectories = ['~/.local/share/nvim/plugged/vim-snippets/UltiSnips', '~/.local/share/nvim/plugged/vim-snippets/snippets']


"I tried to trigger the placeholder back and forth but seems like the only
"default one are working which are ctrl+j and ctrl+k. 



augroup AutoSaveTeX
autocmd!
autocmd BufEnter,BufLeave *.tex,*.bib silent! wall
augroup END


" **********for vimwiki ************
" au filetype vimwiki silent! iunmap <buffer> <Tab>
let g:vimwiki_listsyms = '✗○◐●✓'
" wimwiki always save it automatically, no need to put these.
" Enable auto-saving
"

let All_wiki = {'path': '~/phd_work/notes/vimwiki/All_wiki','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/All_wiki', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/All_wiki/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/All_wiki/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let Research_work = {'path': '~/phd_work/notes/vimwiki/Research_work','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/Research_work', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/Research_work/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/Research_work/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let Lecture_notes = {'path': '~/phd_work/notes/vimwiki/Lecture_notes','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/Lecture_notes', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/Lecture_notes/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/Lecture_notes/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let Tools = {'path': '~/phd_work/notes/vimwiki/Tools','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/Tools', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/Tools/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/Tools/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let old_wiki = {'path': '~/phd_work/notes/vimwiki/old_wiki','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/old_wiki', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/old_wiki/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/old_wiki/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let g:vimwiki_list = [All_wiki,Research_work,Lecture_notes,Tools,old_wiki]
" let g:vimwiki_html_header = '~/vishalrao009.github.io/wiki/vimwiki_html/'
" let g:vimwiki_html_footer = '~/vishalrao009.github.io/wiki/vimwiki_html/'

let g:vimwiki_text_ignore_newline=0 "Newlines in text are converted to <br />s.
nnoremap <leader>w1 :VimwikiIndex 1<CR>
nnoremap <leader>w2 :VimwikiIndex 2<CR>
nnoremap <leader>w3 :VimwikiIndex 3<CR>
nnoremap <leader>w4 :VimwikiIndex 4<CR>
nnoremap <leader>w5 :VimwikiIndex 5<CR>
nnoremap <leader>ot :tabe ~/vishalrao009.github.io/wiki/templates/default_colored.html<CR>


au filetype vimwiki silent! iunmap <buffer> <cr>
"above command will remove the auto creation of bullets and todo and other
"task in vimwiki
nnoremap <leader>ch :noh<CR>
nnoremap <leader>oh :Vimwiki2HTML<CR>
nnoremap <leader>ah :VimwikiAll2HTML<CR>

" let file_name = expand('%:t:r')
let g:vimwiki_current_file = expand('%:t:r')

" nnoremap <leader>ml :source $MYVIMRC<CR>:e ~/vishalrao009.github.io/wiki/vimwiki_html/<C-R>=g:vimwiki_current_file<CR>.html<CR>
" nnoremap <leader>wk :source $MYVIMRC<CR>:e ~/phd_work/notes/vimwiki/<C-R>=g:vimwiki_current_file<CR>.wiki<CR>


"making new tabs in vim 
nnoremap <leader>nt :tabnew<CR>
nnoremap <leader>l :tabnext<CR>
nnoremap <leader>ct :tabclose<CR>
nnoremap <leader>h :tabprevious<CR>
"
au FileType vimwiki syntax enable

function! InsideMathZone()
  for id in synstack(line("."), col("."))
    if synIDattr(id, "name") == "textSnipTEX" || synIDattr(id,"name")=="VimwikiMath"
      return 1
    endif
  endfor
return 0
endfunction

nnoremap <F1> <Cmd>echo synIDattr(synID(line("."), col("."), 1), "name")<CR>

nnoremap <leader>sp :tabe ~/.config/nvim/vim-snippets/snippets<CR>

nnoremap <leader>up :tabe ~/.config/nvim/vim-snippets/UltiSnips<CR>
nnoremap <leader>uu :UltiSnipsEdit<CR>


" mapping ctags keys 
nnoremap <leader>j <C-]>
nnoremap <leader>b <C-T>
nnoremap <leader>gj g<C-]>
" to generate c-tags simply go to SIMULATeQCD folder and type ctags -R (but
" this will generate tags for all files including .html, .js and .md along
" with .h and .cpp files), to avoid it we will use the below command:
"ctags -R --languages=c++,c --exclude=*.txt --exclude=*.md --exclude=*.js --exclude=*.html --exclude=build *



nnoremap <leader>ew <C-w>n
"above is to create a new empty window
nnoremap <leader>nw <C-w>w
" above is to go to split windows of vim
nnoremap <leader>vn :vsp terminal<CR>
nnoremap <leader>sw <C-w>x
"above is to swap the positions of split windows


let g:coc_snippet_next = '<tab>'
let g:coc_snippet_prev='<s-tab>'

let g:UltiSnipsExpandTrigger="<tab>"                                            
let g:UltiSnipsJumpForwardTrigger="<tab>"                                       
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"    

" below are default mappings which work with snippets as expected and not with UltiSnips,
" IDK how? 
" let g:UltiSnipsExpandTrigger='<tab>'
" let g:UltiSnipsListSnippets='<c-tab>'
" let g:UltiSnipsJumpForwardTrigger='<c-j>'
" let g:UltiSnipsJumpBackwardTrigger='<c-k>'

let g:calendar_google_calendar = 1
let g:calendar_google_task = 1


" below for vim-highlighter
let HiSet   = 'f<CR>'
let HiErase = 'f<BS>'
let HiClear = 'f<C-L>'
let HiFind  = 'f<Tab>'
let HiSetSL = 't<CR>'

"to remove the relative numbers 
nnoremap <leader>no :set mouse=i<CR>:setlocal nonumber norelativenumber<CR>

" Set bold and colored highlight for vimwikiHeader1
highlight vimwikiHeader1 ctermfg=red cterm=bold

" Set bold and colored highlight for vimwikiHeader2
highlight vimwikiHeader2 ctermfg=green cterm=bold

" Set bold and colored highlight for vimwikiHeader3
highlight vimwikiHeader3 ctermfg=blue cterm=bold

" Set bold and colored highlight for vimwikiHeader4
highlight vimwikiHeader4 ctermfg=yellow cterm=bold

" Set bold and colored highlight for vimwikiHeader5
highlight vimwikiHeader5 ctermfg=magenta cterm=bold

" Set bold and colored highlight for vimwikiHeader6
highlight vimwikiHeader6 ctermfg=cyan cterm=bold
"mapping ctrl+o to leader+p, ctrl+o is to go to past cursor positions
nnoremap <leader>p <C-O>
nnoremap <leader>tc :VimwikiTOC<CR>
imap ^^ <Esc>[s1z=`]a
"above command will automatically correct the last incorrect spelling

let g:medieval_langs = ['python=python3', 'cpp', 'sh', 'console=bash']  " to execute code blocks
" init.vim
autocmd FileType python inoremap <buffer><silent><C-Space> <C-R>=coc#refresh()<CR>
autocmd FileType python noremap <buffer><silent><C-Space> :call coc#refresh()<CR>

" autocmd FileType vimwiki inoremap <buffer> <expr> <Tab> InsideMathZone() ? "\<Tab>" : "\<C-R>=UltiSnips#ExpandSnippetOrJump()\<CR>"

nnoremap <leader>fv :loadview<CR>
nnoremap <leader>sf :mkview<CR>




Updated on 9th Jan 2025

" To add comments add one double quotes and a space:
set ttyfast  " to fast scrolling of hjkl
set wrap linebreak nolist
set foldmethod=manual " use zf to fold the selected lines, use zo or l to open and zd to delete them
set encoding=utf-8
set nocompatible
filetype plugin on
syntax on
" set mouse=a
set mouse+=a "for active mouse copied to clipboard
set relativenumber
set number
set tabstop=4
set shiftwidth=4
" set clipboard+=unnamedplus
call plug#begin('~/.config/nvim')
"let me see 
"to delete a Plug just delete it from here and call :PlugClean
Plug 'https://github.com/vim-airline/vim-airline' 
Plug 'https://github.com/yuratomo/w3m.vim'
Plug 'nvim-lua/plenary.nvim' 
" Plug 'makerj/vim-pdf' 
" below plug finds the defination of variables, class, functions etc 
Plug 'gpanders/vim-medieval' "to evaluate markdown code blocks
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
Plug 'sheerun/vim-polyglot'
Plug 'jbyuki/quickmath.nvim' 
Plug 'Apeiros-46B/qalc.nvim'
" Plug 'itchyny/calendar.vim'
Plug 'mhinz/vim-startify'
Plug 'SirVer/UltiSnips'
Plug 'honza/vim-snippets'
Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
"to change welcome screen of neovim
Plug 'https://github.com/nvimdev/dashboard-nvim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'nvim-telescope/telescope.nvim' 
Plug 'https://github.com/BurntSushi/ripgrep' 
Plug 'https://github.com/sharkdp/fd'
Plug 'https://github.com/jiangmiao/auto-pairs'
Plug 'azabiong/vim-highlighter'
Plug 'https://github.com/preservim/nerdtree' "use PlugInstall if not installed, then use :NERDtree, :NERDTreefocus and enjoy
Plug 'https://github.com/tpope/vim-commentary' " used to put comments via gcc
Plug 'https://github.com/tpope/vim-surround' "used to see status
Plug 'https://github.com/ap/vim-css-color' " CSS Color Preview
Plug 'https://github.com/rafi/awesome-vim-colorschemes' " Retro Scheme
Plug 'https://github.com/neoclide/coc.nvim'  " Auto Completion
Plug 'https://github.com/preservim/tagbar' "press f8 to see
Plug 'https://github.com/tc50cal/vim-terminal' " Vim Terminal
" Plug 'https://github.com/terryma/vim-multiple-cursors' " CTRL + N for multiple cursors
Plug 'morhetz/gruvbox'
"above plugin are copied from NeuralNine youtube channel creator:
"https://github.com/NeuralNine/config-files/blob/master/init.vim
Plug 'https://github.com/kassio/neoterm'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" Add this line to your vimrc
Plug 'https://github.com/lervag/vimtex' 
" Plug 'duane9/nvim-rg' " it is dependency for live_grep. 
Plug 'https://github.com/ryanoasis/vim-devicons' " Developer Icons: always load this plug in the end. 

call plug#end()

"below lines are added for cuda 
au BufNewFile,BufRead *.cu set filetype=cuda
au BufNewFile,BufRead *.cuh set filetype=cuda
let mapleader=","
let maplocalleader = ","
" set my mapleader to "," if you want to know more about mapleader enter :h mapleader in Vim
inoremap jk <Esc>
let file_type = &filetype
let filepath = expand('%:p')
let filename = expand('%:t:r')

if file_type == 'vim'
nnoremap <leader>c :w<CR>:source $MYVIMRC<CR>
elseif file_type == 'c'
nnoremap <leader>c :w<CR>:!gcc <C-R>=filepath<CR> -o %:t:r <CR>:T bash<CR><CR>i
"&& time ./a.out<CR>
elseif file_type == 'cpp'
nnoremap <leader>c :w<CR>:!g++ <C-R>=filepath<CR> -o %:t:r <CR>:T bash<CR><CR>i
"&& time ./a.out<CR>
elseif file_type == 'cuda'
nnoremap <leader>c :w<CR>:!nvcc <C-R>=filepath<CR> -o %:t:r <CR>:T bash<CR><CR>i
"&& time ./a.out<CR>
elseif file_type == 'python'
nnoremap <leader>c :w<CR>:!python <C-R>=filepath<CR><CR>i:T bash<CR><CR>i
endif
"it turns out that to quickly open files we shall not execute init.vim each
"time, so I am calling the sourcing of init.vim only when we want to
"execute the code. 

" autocmd BufEnter *.c,*.cpp,*.cu,*.py if file_type ==# 'c' || file_type ==# 'cpp' || file_type ==# 'cuda' || file_type ==# 'python' | source $MYVIMRC | endif
" 
" The above commented auto reload did not work, it was 
"
" Your other custom mappings and configurations
"

" Autocommand to reload the configuration when a new buffer is loaded
" Auto-reload Vim configuration when switching between specific filetypes

" Other settings and configurations


"<CR> is used to press enter
" <C-R>= is used to insert the value of an expression. In this case, it's used to insert the value of g:current_file.


" please don't put space after the <esc> keyword above # to enter into normal mode just press jk in insert mode. 
" to run the cuda program after editing, just write the 'Rc' short for goto
" normal mode and run cuda.
"
" ********************IF you want to create specific executables with program
" name istead of ./a.out*************************************, 
"if file_type == 'vim'
" nnoremap <leader>r :w<CR>:source $MYVIMRC<CR>
" elseif file_type == 'c'
" nnoremap <leader>r :w<CR>:!gcc <C-R>=filepath<CR> -o %:t:r && time ./<C-R>=filename<CR><CR>
" elseif file_type == 'cpp'
" nnoremap <leader>r :w<CR>:!g++ <C-R>=filepath<CR> -o %:t:r && time ./<C-R>=filename<CR><CR>
" elseif file_type == 'cuda'
" nnoremap <leader>r :w<CR>:!nvcc <C-R>=filepath<CR> -o %:t:r && time ./<C-R>=filename<CR><CR>
" elseif file_type == 'python'
" nnoremap <leader>r :w<CR>:!python <C-R>=filepath<CR><CR>
" endif

"
" hi Normal ctermbg=16
set t_Co=256
" the above command is equivalent to ctrl+t to toggle NERDtree. 
" leader means "\" 


" I use below configuration for open and edit and reload my dot vimrc file:
nnoremap <leader>fmi :set foldmethod=indent<CR>

nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>ft :Telescope find_files<CR>
nnoremap <leader>fzf :FZF<CR>
" nnoremap <leader>tz :TerminalVSplit zsh<CR><CR>
"I am not using telescope for the moment and have setting fuzzyfinder which
"is triggered by keys 'fzf' in normal mode. you can uncomment telescope
"command to use that too. 
" nnoremap <leader>tv :TerminalVSplit bash<CR><CR>
" nnoremap <leader>t  :T bash<CR><CR>i
" nnoremap <leader>th :TerminalSplit bash<CR><CR>
nnoremap <leader>z :w!<CR>:suspend<CR> 
nnoremap <leader>ff :NERDTreeToggle<CR>
nnoremap <leader>nt :NERDTree<CR>
nnoremap <leader>vm :tabe $MYVIMRC<CR>
nnoremap <leader>ep :tabe /root/project1/SIMULATeQCD/src/examples/main_plaquette.cpp<CR>
" nnoremap <leader>hyp :tabe /root/project1/SIMULATeQCD/src/modules/hyp/<CR>
nnoremap <leader>kn :tabe /root/project1/SIMULATeQCD/src/gauge/gauge_kernels.cpp<CR>

" Open my vimrc file in vertical tab whenever I pressed ,vm
nnoremap <leader>sv :w<CR>:source $MYVIMRC<CR>
inoremap <leader>sv <esc>:w<CR>:source $MYVIMRC<CR>i
tnoremap <leader>q <C-\><C-d>
tnoremap <leader>nw <C-w>w
" Reload my vimrc file whenever I pressed ,sv and we will go to normal mode,
" then source our vim file, and get back to insert mode.
nnoremap <leader>ss :w!<CR>   
" Save my current file with ,w instead of typing :w every time.
nnoremap<leader>q :q!<CR>
" to quit my file with ,q rather than with :q
nnoremap<leader>wq :wq!<CR>
nnoremap<leader>sq :wq!<CR>
" to save and quit the current fiile with ,wq rather than with :wq 
" 3<leader>tl will clear neoterm-3, use comma and tl to get terminal, insert
" commands and once done, hit exit enter,
" one alternative to use terminal after code is to use ctrl+z or set
" keybinding to ctrl+z to pause vim and play in terminal and use fg+enter to
" get back to where we were in vim.
" nnoremap <leader>tl :<c-u>exec v:count.'Tclear'<cr>
" let NERDTreeShowHidden=1
"To toggle between hidden files, use shift+i for the nerdtree. 
"
"the above command is set to show the hidden items of the directory
" :source $MYVIMRC
"
"
" let g:python3_host_prog = '/usr/bin/python'
" let g:python3_host_prog = '/Users/vishalrao/.pyenv/versions/3.9.10/bin/python3'
" uncomment the upper line for use in macOS.

let g:loaded_ruby_provider = 0
nnoremap <leader>dm :set background=dark<CR>:colorscheme gruvbox<CR>
"key to day/dark mode is just <leader>dm


nnoremap <leader>nm :set background=light<CR>:colorscheme morning<CR>
"  key for night mode is just <leader>nm
"
set background =light
" set background=light
" :colorscheme PaperColor
" :colorscheme alduin
" :colorscheme deus 
" :colorscheme deep-space
" :colorscheme apprentice
" :colorscheme slate 
" :colorscheme sierra
" :colorscheme delek 
" :colorscheme desert
" :colorscheme nord 
" :colorscheme hybrid_material 
" :colorscheme molokayo 
" :colorscheme molokai  
" :colorscheme happy_hacking 
" :colorscheme materialbox 
" :colorscheme gotham 
:colorscheme morning 
" :colorscheme gruvbox

" let g:NERDTreeDirArrowExpandable="+"
" let g:NERDTreeDirArrowCollapsible="~"
nnoremap <C-l> :call CocActionAsync('jumpDefinition')<CR>

nmap <F8> :TagbarToggle<CR>
:set completeopt-=preview " For No Previews
let g:airline_powerline_fonts = 1

if !exists('g:airline_symbols')
  let g:airline_symbols = {}
endif
" airline symbols
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''



"
"************************************LATEX SECTION OF init.vim***************************************
"
" This is necessary for VimTeX to load properly. The "indent" is optional.
" Note that most plugin managers will do this automatically.
filetype plugin indent on

let g:vimtex_view_method = 'zathura'
" This enables Vim's and neovim's syntax-related features. Without this, some
" VimTeX features will not work (see ":help vimtex-requirements" for more
" info).
syntax enable

" Viewer options: One may configure the viewer either by specifying a built-in
" viewer method:
let g:vimtex_view_method = 'zathura'

" Or with a generic interface:
let g:vimtex_view_general_viewer = 'okular'
let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'

" VimTeX uses latexmk as the default compiler backend. If you use it, which is
" strongly recommended, you probably don't need to configure anything. If you
" want another compiler backend, you can change it as follows. The list of
" supported backends and further explanation is provided in the documentation,
" see ":help vimtex-compiler".
let g:vimtex_compiler_method = 'latexrun'

" Most VimTeX mappings rely on localleader and this can be changed with the
" following line. The default is usually fine and is the symbol "\".



" ***********************************COC.NVIM******************************

" May need for Vim (not Neovim) since coc.nvim calculates byte offset by count
" utf-8 byte sequence
set encoding=utf-8
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup

" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
" delays and poor user experience
set updatetime=300

" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved
set signcolumn=yes

" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config
inoremap <silent><expr> <TAB>
    \ coc#pum#visible() ? coc#pum#next(1) :
    \ CheckBackspace() ? "\<Tab>" :
    \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
                            \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif

" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>

function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
  call CocActionAsync('doHover')
else
  call feedkeys('K', 'in')
endif
endfunction

" Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')

" Symbol renaming
nmap <leader>rn <Plug>(coc-rename)

" Formatting selected code
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s)
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

" Applying code actions to the selected code block
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)

" Remap keys for applying code actions at the cursor position
nmap <leader>ac  <Plug>(coc-codeaction-cursor)
" Remap keys for apply code actions affect whole buffer
nmap <leader>as  <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line
nmap <leader>fc  <Plug>(coc-fix-current)

" Remap keys for applying refactor code actions
nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
xmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)
nmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)

" Run the Code Lens action on the current line
nmap <leader>cl  <Plug>(coc-codelens-action)

" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)

" Remap <C-f> and <C-b> to scroll float windows/popups
if has('nvim-0.4.0') || has('patch-8.2.0750')
  nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif

" Use CTRL-S for selections ranges
" Requires 'textDocument/selectionRange' support of language server
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)

" Add `:Format` command to format current buffer
command! -nargs=0 Format :call CocActionAsync('format')

" Add `:Fold` command to fold current buffer
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer
command! -nargs=0 OR   :call     CocActionAsync('runCommand', 'editor.action.organizeImport')

" Add (Neo)Vim's native statusline support
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

" Mappings for CoCList
" Show all diagnostics
nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item
nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item
nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>




"******************VIM-SNIPPETS and UltiSnips**************
" For example, I use the following configuration:
" let g:UltiSnipsSnippetDirectories = ['~/.local/share/nvim/plugged/vim-snippets/UltiSnips', '~/.local/share/nvim/plugged/vim-snippets/snippets']


"I tried to trigger the placeholder back and forth but seems like the only
"default one are working which are ctrl+j and ctrl+k. 



augroup AutoSaveTeX
autocmd!
autocmd BufEnter,BufLeave *.tex,*.bib silent! wall
augroup END


" **********for vimwiki ************
" au filetype vimwiki silent! iunmap <buffer> <Tab>
let g:vimwiki_listsyms = '✗○◐●✓'
" wimwiki always save it automatically, no need to put these.
" Enable auto-saving
"

let All_wiki = {'path': '~/phd_work/notes/vimwiki/All_wiki','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/All_wiki', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/All_wiki/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/All_wiki/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let Research_work = {'path': '~/phd_work/notes/vimwiki/Research_work','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/Research_work', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/Research_work/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/Research_work/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let Blogs = {'path': '~/phd_work/notes/vimwiki/Blogs','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/Blogs', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/Blogs/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/Blogs/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let Lecture_notes = {'path': '~/phd_work/notes/vimwiki/Lecture_notes','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/Lecture_notes', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/Lecture_notes/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/Lecture_notes/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let Tools = {'path': '~/phd_work/notes/vimwiki/Tools','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/Tools', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/Tools/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/Tools/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let old_wiki = {'path': '~/phd_work/notes/vimwiki/old_wiki','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/old_wiki', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/old_wiki/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/old_wiki/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let SIMULATeQCD = {'path': '~/phd_work/notes/vimwiki/SIMULATeQCD','path_html':'~/vishalrao009.github.io/wiki/vimwiki_html/SIMULATeQCD', 'syntax': 'default', 'ext': '.wiki','html_header':'~/vishalrao009.github.io/wiki/vimwiki_html/old_wiki/header.html','html_footer':'~/vishalrao009.github.io/wiki/vimwiki_html/SIMULATeQCD/footer.html','template_path':'~/vishalrao009.github.io/wiki/templates','template_default':'default_colored','template_ext':'.html'}
let g:vimwiki_list = [All_wiki,Blogs,Research_work,Lecture_notes,Tools,old_wiki,SIMULATeQCD]
" let g:vimwiki_html_header = '~/vishalrao009.github.io/wiki/vimwiki_html/'
" let g:vimwiki_html_footer = '~/vishalrao009.github.io/wiki/vimwiki_html/'

let g:vimwiki_text_ignore_newline=0 "Newlines in text are converted to <br />s.
nnoremap <leader>w0 :VimwikiIndex 1<CR>
nnoremap <leader>w1 :VimwikiIndex 2<CR>
nnoremap <leader>w2 :VimwikiIndex 3<CR>
nnoremap <leader>w3 :VimwikiIndex 4<CR>
nnoremap <leader>w4 :VimwikiIndex 5<CR>
nnoremap <leader>w5 :VimwikiIndex 6<CR>
nnoremap <leader>w6 :VimwikiIndex 7<CR>
nnoremap <leader>ot :tabe ~/vishalrao009.github.io/wiki/templates/default_colored.html<CR>


au filetype vimwiki silent! iunmap <buffer> <cr>
"above command will remove the auto creation of bullets and todo and other
"task in vimwiki
nnoremap <leader>ch :noh<CR>
nnoremap <leader>oh :Vimwiki2HTML<CR>
nnoremap <leader>ah :VimwikiAll2HTML<CR>

" let file_name = expand('%:t:r')
let g:vimwiki_current_file = expand('%:t:r')

" nnoremap <leader>ml :source $MYVIMRC<CR>:e ~/vishalrao009.github.io/wiki/vimwiki_html/<C-R>=g:vimwiki_current_file<CR>.html<CR>
" nnoremap <leader>wk :source $MYVIMRC<CR>:e ~/phd_work/notes/vimwiki/<C-R>=g:vimwiki_current_file<CR>.wiki<CR>


"making new tabs in vim 
nnoremap <leader>nt :tabnew<CR>
nnoremap <leader>l :tabnext<CR>
nnoremap <leader>ct :tabclose<CR>
nnoremap <leader>h :tabprevious<CR>
"
au FileType vimwiki syntax enable

function! InsideMathZone()
  for id in synstack(line("."), col("."))
    if synIDattr(id, "name") == "textSnipTEX" || synIDattr(id,"name")=="VimwikiMath"
      return 1
    endif
  endfor
return 0
endfunction

nnoremap <F1> <Cmd>echo synIDattr(synID(line("."), col("."), 1), "name")<CR>

nnoremap <leader>sp :tabe ~/.config/nvim/vim-snippets/snippets<CR>

nnoremap <leader>up :tabe ~/.config/nvim/vim-snippets/UltiSnips<CR>
nnoremap <leader>uu :UltiSnipsEdit<CR>


" mapping ctags keys 
nnoremap <leader>j <C-]>
nnoremap <leader>b <C-T>
nnoremap <leader>gj g<C-]>
" to generate c-tags simply go to SIMULATeQCD folder and type ctags -R (but
" this will generate tags for all files including .html, .js and .md along
" with .h and .cpp files), to avoid it we will use the below command:
"ctags -R --languages=c++,c --exclude=*.txt --exclude=*.md --exclude=*.js --exclude=*.html --exclude=build *



nnoremap <leader>ew <C-w>n
"above is to create a new empty window
nnoremap <leader>nw <C-w>w
" above is to go to split windows of vim
nnoremap <leader>vn :vsp terminal<CR>
nnoremap <leader>sw <C-w>x
"above is to swap the positions of split windows


let g:coc_snippet_next = '<tab>'
let g:coc_snippet_prev='<s-tab>'

let g:UltiSnipsExpandTrigger="<tab>"                                            
let g:UltiSnipsJumpForwardTrigger="<tab>"                                       
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"    

" below are default mappings which work with snippets as expected and not with UltiSnips,
" IDK how? 
" let g:UltiSnipsExpandTrigger='<tab>'
" let g:UltiSnipsListSnippets='<c-tab>'
" let g:UltiSnipsJumpForwardTrigger='<c-j>'
" let g:UltiSnipsJumpBackwardTrigger='<c-k>'

let g:calendar_google_calendar = 1
let g:calendar_google_task = 1


" below for vim-highlighter
let HiSet   = 'f<CR>'
let HiErase = 'f<BS>'
let HiClear = 'f<C-L>'
let HiFind  = 'f<Tab>'
let HiSetSL = 't<CR>'

"to remove the relative numbers 
nnoremap <leader>no :set mouse=i<CR>:setlocal nonumber norelativenumber<CR>

" Set bold and colored highlight for vimwikiHeader1
highlight vimwikiHeader1 ctermfg=red cterm=bold

" Set bold and colored highlight for vimwikiHeader2
highlight vimwikiHeader2 ctermfg=green cterm=bold

" Set bold and colored highlight for vimwikiHeader3
highlight vimwikiHeader3 ctermfg=blue cterm=bold

" Set bold and colored highlight for vimwikiHeader4
highlight vimwikiHeader4 ctermfg=yellow cterm=bold

" Set bold and colored highlight for vimwikiHeader5
highlight vimwikiHeader5 ctermfg=magenta cterm=bold

" Set bold and colored highlight for vimwikiHeader6
highlight vimwikiHeader6 ctermfg=cyan cterm=bold
"mapping ctrl+o to leader+p, ctrl+o is to go to past cursor positions
nnoremap <leader>p <C-O>
nnoremap <leader>tc :VimwikiTOC<CR>
imap ^^ <Esc>[s1z=`]a
"above command will automatically correct the last incorrect spelling

let g:medieval_langs = ['python=python3', 'cpp', 'sh', 'console=bash']  " to execute code blocks
" init.vim
autocmd FileType python inoremap <buffer><silent><C-Space> <C-R>=coc#refresh()<CR>
autocmd FileType python noremap <buffer><silent><C-Space> :call coc#refresh()<CR>

" autocmd FileType vimwiki inoremap <buffer> <expr> <Tab> InsideMathZone() ? "\<Tab>" : "\<C-R>=UltiSnips#ExpandSnippetOrJump()\<CR>"

nnoremap <leader>fv :loadview<CR>
nnoremap <leader>sf :mkview<CR>
 " for use of internet in vim itself
" let g:w3m#command = 'C:\w3m.exe'
"
"
"
" Map <F5> to save and run the selected code
vnoremap <F5> :w<CR>:!bash -c 'echo "Running selection:" && cat > /tmp/vim_tmp.sh && chmod +x /tmp/vim_tmp.sh && /tmp/vim_tmp.sh'<CR>
" Save and run selected C++ code with <F6> in visual mode
vnoremap <leader>pp :w! /tmp/vim_cpp_exec.cpp<CR>:!g++ -std=c++20 /tmp/vim_cpp_exec.cpp -o /tmp/vim_cpp_exec && /tmp/vim_cpp_exec<CR>


vnoremap <leader>py :w! /tmp/vim_py_exec.py<CR>:!python /tmp/vim_py_exec.py<CR>